package com.example.dllo.moondog.information;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.dllo.moondog.R;
import com.example.dllo.moondog.base.BaseFragment;
import com.example.dllo.moondog.information.exercise.ExerciseFragment;
import com.example.dllo.moondog.information.newsss.NewFragment;
import com.example.dllo.moondog.information.official.OfficialFragment;
import com.example.dllo.moondog.information.strategy.StrategyFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/3/2.
 */
public class InformationFragment extends BaseFragment {
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private List<Fragment> data;
    private InformationAdapter adapter;
    private Context context;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_information,null);
        return view;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        tabLayout = (TabLayout) getActivity().findViewById(R.id.tabLayout_information);
        viewPager = (ViewPager) getActivity().findViewById(R.id.viewPager_information);

        data = new ArrayList<>();
        data.add(new NewFragment());
        data.add(new OfficialFragment());
        data.add(new ExerciseFragment());
        data.add(new StrategyFragment());

        adapter = new InformationAdapter(getActivity().getSupportFragmentManager(),data,context);
        viewPager.setAdapter(adapter);
        tabLayout.setTabTextColors(Color.BLACK, Color.BLUE);
        tabLayout.setupWithViewPager(viewPager);
    }
}
